import time

from selenium.webdriver.common.by import By

import page
from base.base import Base
from util import read_json


class PageWebOrder(Base):
    def page_web_order_menu(self):
        self.base_click(page.web_order)

    def page_web_order_delivery(self):
        self.base_click(page.web_order_delivery)

    def page_web_go_delivery(self):
        self.base_switch_frame(page.web_order_iframe)
        loc = By.XPATH, page.web_order_go_delivery.format(read_json("expect.json", "expect")[0][0])
        self.base_click(loc)

    def page_web_company(self):
        self.base_click(page.web_order_company)

    def page_web_dorder_on(self):
        order_on = str(time.strftime("%Y%m%d%H%M%S"))
        self.base_input(page.web_order_order_on,order_on)

    def page_web_goods_ok(self):
        self.base_click(page.web_order_goods_ok)

    def page_web_print_order(self):
        self.base_click(page.web_order_print_order)

    def page_web_get_order_on(self):
        return self.base_get_text(page.web_order_on)

    def page_web_delivery(self,):
        self.page_web_order_menu()
        self.page_web_order_delivery()
        self.page_web_go_delivery()
        self.page_web_company()
        self.page_web_dorder_on()
        self.page_web_goods_ok()
        self.page_web_print_order()
        self.page_web_get_order_on()
